package vn.aptech.leaveManagementSystem.business.model;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import vn.aptech.leaveManagementSystem.dao.DBManager;

public class Configurations extends DBManager{
	//Configuration ID = 1: Maximum number ofdays in one year is allowed for leaving.
	//Configuration ID = 2: the time, which you apply leave application,  must before the day which you leave is [n] days
	//Configuration ID = 3: The number of records displayed in the one data table on the form.("The minimum period " which use to view and browse the leave application)
	public int getMaxNumDaysAllowLeaving() throws SQLException
	{
		getConn();
		String sql="{Call sp_getConfiguration(?)}";
		CallableStatement cs=conn.prepareCall(sql);
		cs.setInt(1, 1);
		ResultSet rs=cs.executeQuery();
		rs.next();
		return rs.getInt("Parameter");
	}
	
	public int getMinPeriodToBrowseApp() throws SQLException
	{
		getConn();
		String sql="{Call sp_getConfiguration(?)}";
		CallableStatement cs=conn.prepareCall(sql);
		cs.setInt(1, 2);
		ResultSet rs=cs.executeQuery();
		rs.next();
		return rs.getInt("Parameter");
	}
	
	public int getNumOfRecordsDisplayOnPage() throws SQLException 
	{
		getConn();
		String sql="{Call sp_getConfiguration(?)}";
		CallableStatement cs=conn.prepareCall(sql);
		cs.setInt(1, 3);
		ResultSet rs=cs.executeQuery();
		rs.next();
		return rs.getInt("Parameter");
	}
	
	public ResultSet getConfigurationsList() throws SQLException
	//Configuration.*
	{
		getConn();
		String sql="{Call sp_showConfigurationsList}";
		CallableStatement cs=conn.prepareCall(sql);
		return cs.executeQuery();
	}
}
